package com.dhj.optionalTest;

import com.dhj.streamTest.entity.Author;

import java.util.Optional;

/**
 * Optional的map方法，数据转换
 */
public class Demo5 {

    public static void main(String[] args) {
        Author author = getAuthor();
        Optional<Author> optional = Optional.ofNullable(author);

        optional.map(author1 -> author1.getName()).ifPresent(name -> System.out.println(name));

    }


    public static Author getAuthor() {
        Author author = new Author(5L, "林则徐1", 65, "苟利国家生死以", null);
        return author;
    }


    public static Author getAuthor2() {
        return null;
    }

}
